#ifndef MODEL_VALIDATOR_H
#define MODEL_VALIDATOR_H

#include <icontainerdocument.h>

#include <QtCore/QHash>
#include <QtCore/QObject>
#include <QtCore/QSharedPointer>

QT_BEGIN_NAMESPACE
class QAction;
class QModelIndex;
class QStandardItemModel;
QT_END_NAMESPACE

namespace core
{
class MimeType;
}

namespace swp
{
class IValidatorRule;

class ModelValidator : public QObject
{
    Q_OBJECT

public:
    static ModelValidator* getInstance();
    static void destroy();

    void addRule(IValidatorRule* rule, const core::MimeType& forType);

    QStandardItemModel* report() const;

private:
    ModelValidator();
    ~ModelValidator();

    QSharedPointer<core::IDocument> getDocument(QAction* action) const;

signals:
    void validatingStarted();
    void validatingFinished();
    void selectProjectRequest(
        QSharedPointer<core::IContainerDocument> project);
    void highlightDocumentRequest(
        QSharedPointer<core::IDocument> project);

public slots:
    void validate(const QSharedPointer<core::IContainerDocument>& project);
    void handleReportItemActivation(const QModelIndex& index);
    void actionAboutToTrigger(QAction* action);

private slots:
    void selectDocument();
    void selectProject();
    void deselectItems();

private:
    QHash<QString, QList<IValidatorRule* > > m_rules;
    QHash<QAction*, QAction* > m_parentActionMapping;
    QStandardItemModel* m_report;
    QList<QAction* > m_selectActions;
    QSharedPointer<core::IContainerDocument> m_validatedProject;
};

} // namespace swp

#endif
